package evolution.executor;

import evolution.algorithm.EvolutionaryAlgorithm;
import evolution.algorithm.Iterative;
import evolution.stop.StopCondition;

public class EvolutionaryAlgorithmRunner implements Runnable {

	private EvolutionaryAlgorithm evolutionaryAlgorithm;
	private StopCondition<Iterative> stopCondition;

	public EvolutionaryAlgorithmRunner(
			EvolutionaryAlgorithm evolutionaryAlgorithm,
			StopCondition<Iterative> stopCondition) {
		this.evolutionaryAlgorithm = evolutionaryAlgorithm;
		this.stopCondition = stopCondition;
	}

	@Override
	public void run() {
		while (!stopCondition.shouldStop(evolutionaryAlgorithm)) {
			evolutionaryAlgorithm.runIteration();
		}
	}

	public EvolutionaryAlgorithm getEvolutionaryAlgorithm() {
		return evolutionaryAlgorithm;
	}

	public void setEvolutionaryAlgorithm(
			EvolutionaryAlgorithm evolutionaryAlgorithm) {
		this.evolutionaryAlgorithm = evolutionaryAlgorithm;
	}

	public StopCondition<Iterative> getStopCondition() {
		return stopCondition;
	}

	public void setStopCondition(StopCondition<Iterative> stopCondition) {
		this.stopCondition = stopCondition;
	}
}
